/*! \file MceIrSession.h holds the Tcp protocol.
 *
 *  This is a work in progres and the protocol can change at any time.
 *
 */
#ifndef __MCE_IR_SESSION_INCLUDED__
#define __MCE_IR_SESSION_INCLUDED__

#include "TcpSession.h"
#include "DriverManager.h"

#include <string>

/*! \brief MceIrSession holds the Tcp Protocol details.
 *
 *  Protocol is \\r\\n terminated and can only contain ASCII characters, 
 *  no NULL's. Any binary data must be HEX encoded. The parameter delimiter is the ' ' space character.
 *
 *  - command [i] returns service identifier: [i OpenMceIrServer 0.1]
 *  - command [l] sets learn mode. returns [l OK]
 *  - command [n] sets learn mode. returns [n OK]
 *  - command [t blasters repeats CCFcode] transmits an IR code. returns [t OK] or [t error [desc]]
 *  - command [b] gets the available blasters. returns [b XXX] where XXX is the blaster bitmask.
 *  - command [s] returns [s HARDWARE_CONNECTED] or [s HARDWARE_NOT_CONNECTED].
 *  - command [c hardwareIndex deviceIndex] restarts the driver attempting to load the hardware and device with indexes given. These values are stored in the registry for next startup. Returns [c OK]
 *  - command [q] closes the connection, the services continues running.
 *
 *  unknown commands return [e Unknown Command]
 *
 *  An IR event is signaled by the command [R PROTOCOL KEYNAME]
 */
class MceIrSession : public TcpSession
{
protected:
	bool dataReceived ( const char * data, size_t len );
	void irReceived ( DWORD code, DWORD key, DWORD repeat, const char * name );
	int m_irReceiveId;
	void recordToFile();
	void transmit (const std::string & data);
	void status ();
	void blasters();
	DriverManager * m_DriverManager;
public:
	MceIrSession(boost::asio::io_service& io_service, DriverManager * driverManager);
	~MceIrSession();
	void start();
};

#endif